function login() {

    $.ajax({
        url: "/shop/login",
        type: "POST",
        data: {
            "username": $("#username").val(),
            "password": $("#password").val()
        },
        success: function (response) {
            if (response == null || response == "") {
                alert("登陆失败！！");

            } else {
                sessionStorage.setItem("user", JSON.stringify(response));
                window.location.href = "/page/index.jsp";
            }
        },
        error: function (err) {
            console.log(err);
        }
    })
}

//时间戳转换方法    date:时间戳数字
function formatDate(date) {
    var date = new Date(date);
    var YY = date.getFullYear() + '-';
    var MM = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
    var DD = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
    var hh = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
    var mm = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
    var ss = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
    return YY + MM + DD + " " + hh + mm + ss;
}

//两个日期相差天数
function getDaysBetween(dateString1, dateString2) {
    var startDate = Date.parse(dateString1);
    var endDate = Date.parse(dateString2);
    var days = (endDate - startDate) / (1 * 24 * 60 * 60 * 1000);
    // alert(days);
    return days;
}


